﻿using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using 样式.Model;
using 样式.ViewModel;


namespace 样式
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            this.DataContext = new MainViewModel();
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            var vm = DataContext as MainViewModel;

            if (vm == null) return;

            Person person = new Person();
            person.Name = "新人";
            person.Age = new Random().Next(19, 21);
            person.Address = DateTime.Now.ToString();

            vm.Persons.Add(person);
        }

        private void Button_Click2(object sender, RoutedEventArgs e)
        {
            var vm = DataContext as MainViewModel;

            if (vm == null) return;

            Person person = new Person();
            person.Name = "张三";
            person.Age =20 ;
            person.Address = DateTime.Now.ToString();

            vm.Persons.Add(person);

            Person person2 = new Person();
            person2.Name = "里斯";
            person2.Age = 20;
            person2.Address = DateTime.Now.ToString();

            vm.Persons.Add(person2);
        }
    }
}